define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupons/coupons/index' + location.search,
                    add_url: 'coupons/coupons/add',
                    edit_url: 'coupons/coupons/edit',
                    del_url: 'coupons/coupons/del',
                    multi_url: 'coupons/coupons/multi',
                    import_url: 'coupons/coupons/import',
                    table: 'coupons',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),sortable:true},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'staffnumber', title: __('Staffnumber'), operate: 'LIKE'},
                        {field: 'unionid', title: __('Unionid'), operate: 'LIKE'},
                        {field: 'couponcategory.nametext', title: '关联优惠券类型'},
                        {field: 'begintime', title: __('Begintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'qrcodeimage', title: __('Qrcodeimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'platform', title: __('Platform'), searchList: {"1":__('Platform 1'),"2":__('Platform 2')}, formatter: Table.api.formatter.normal},
                        {field: 'clinic_id', title: __('Clinic_id')},
                        {field: 'statusdata', title: __('Statusdata'), searchList: {"0":__('Statusdata 0'),"1":__('Statusdata 1'),"2":__('Statusdata 2'),"3":__('Statusdata 3')}, formatter: Table.api.formatter.normal},
                        {field: 'appointmenttime', title: __('Appointmenttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,sortable: true},
                        {field: 'finishtime', title: __('Finishtime'),operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,sortable: true},
                        {field: 'user_id', title: __('User_id'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // $("#c-platform").data("eSelect", function(data){
            //     //后续操作
            //     console.log(data);
            //     if(data==1){
                    
            //     }
            // });
            Controller.api.bindevent();
            $("#c-platform").change(function () {
                var platform_type = $("#c-platform").val();
                console.log(platform_type);
                if (platform_type ==1) {
                    $("#c-unionid-c").hide();
                    $("#c-staffnumber-c").show();
                    $("#c-name-c").show();
                } else {
                    $("#c-staffnumber-c").hide();
                    $("#c-name-c").hide();
                    $("#c-unionid-c").show();
                }
            });
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});